package com.example.mytodo

import android.content.ContentValues
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.util.Log
import android.view.View
import androidx.fragment.app.Fragment
import com.example.mytodo.ClockFragment
import com.example.mytodo.MeFragment
import com.example.mytodo.R
import com.example.mytodo.TodoFragment
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    //TODO 做完与否更新颜色

    val TAG = "@@MainActivity"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        replaceFragment(TodoFragment())

        btn_todo.setOnClickListener{
            //btn_todo.setBackgroundColor(R.string.background_color)
            replaceFragment(TodoFragment())
        }
        btn_clock.setOnClickListener{

            //btn_clock.setBackgroundColor(R.string.background_color)
            replaceFragment(ClockFragment())
        }
        btn_me.setOnClickListener{
            // btn_me.setBackgroundColor(R.string.background_color)
            replaceFragment(MeFragment())
        }




    }



    override fun onStart(){
        super.onStart()
        println("onStart")
        Log.d(ContentValues.TAG,"onDestory")
    }
    override fun onPause(){
        super.onPause()

        println("onPause")
        Log.d(ContentValues.TAG,"onPause")
    }
    override fun onRestart(){
        super.onRestart()
        println("onRestart")
        Log.d(ContentValues.TAG,"onRestart")
    }
    override fun onResume(){
        super.onResume()
        println("onResume")
        Log.d(ContentValues.TAG,"onResume")
    }
    override fun onStop(){
        super.onStop()
        println("onStop")
        Log.d(ContentValues.TAG,"onStop")
    }
    override fun onDestroy(){
        super.onDestroy()
        println("onDestroy")
        Log.d(ContentValues.TAG,"onDestory")
    }


    private fun replaceFragment(fragment: Fragment) {
        val fragmentManager = supportFragmentManager
        val transaction = fragmentManager.beginTransaction()
        transaction.replace(R.id.framelayout_upContainer,fragment)
        transaction.commit()

    }

}